package net.atomtree.controller;

import net.atomtree.entity.NoteResult;
import net.atomtree.service.IndexService1;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by czk on 2015/12/27.
 */
@Controller
@RequestMapping("/engine")
public class SpeedController1 {
    @RequestMapping("/speed.do")
    @ResponseBody
    public NoteResult speedIndex() {
        NoteResult result = new NoteResult();
        StringBuffer url = new StringBuffer();
        url.append("http://101.204.243.107:4040/api/v1");
        IndexService1 index = new IndexService1();
        JSONObject stageJson;
        try {
            stageJson = index.countSpeed(url);
            System.out.println("得到stageJson对象");
            if (null == stageJson || stageJson.equals("")) {
//                resp.getWriter().write("");
                result.setStatus(0);
            } else {
                result.setStatus(1);
                result.setData(stageJson);
            }
            return result;
        } catch (Exception e) {
            System.out.println("url解析错误或服务没有启动");
            e.printStackTrace();
        }
        System.out.println("result:"+result);
        return result;
    }
}